<?php
namespace app\common\service;

use yii\helpers\Html;

class UtilService
{
    public static function getIp()
    {
        if( !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ){
            return $_SERVER['HTTP_X_FOREARDED_FOR'];
        }
        return $_SERVER['REMOTE_ADDR'];
    }

    public static function encode( $display )
    {
        return Html::encode( $display );
    }

    public static function getRootPath()
    {
        return dirname(\Yii::$app->vendorPath);
    }

    public static function buildPicUrl( $bucket,$image_key )
    {
        $domain_config = \Yii::$app->params['domain'];
        $upload_config = \Yii::$app->params['upload'];

        return $domain_config['www'].$upload_config[ $bucket ]."/".$image_key;
    }

    public static function isWechat()
    {
        $ug = isset( $_SERVER['HTTP_USER_AGENT'] )?$_SERVER['HTTP_USER_AGENT']:"";
        if( stripos($ug,'micromessenger') !== false ){
            return true;
        }
        return false;
    }
}